package com.chinasoft.mall.activity.subActivity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Observable;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chinasoft.mall.R;
import com.chinasoft.mall.activity.BaseObserverActivity;
import com.chinasoft.mall.activity.GoodsListFromHomeActivity;
import com.chinasoft.mall.activity.MainActivity;
import com.chinasoft.mall.activity.StaffLoginActivity;
import com.chinasoft.mall.activity.SyModelList2Activity;
import com.chinasoft.mall.activity.SyPdMoreActivity;
import com.chinasoft.mall.activity.adapter.GallaryImplAdapter;
import com.chinasoft.mall.activity.adapter.GallaryidImplAdapter;
import com.chinasoft.mall.activity.subActivity.goods.GoodsDetailActivity;
import com.chinasoft.mall.activity.subActivity.goods.GoodsListActivity;
import com.chinasoft.mall.framework.BeanCache;
import com.chinasoft.mall.framework.Config;
import com.chinasoft.mall.framework.ControllerCenter;
import com.chinasoft.mall.framework.LivingGoods;
import com.chinasoft.mall.model.BaseBean;
import com.chinasoft.mall.model.response.EpgBean;
import com.chinasoft.mall.model.response.RechnBean;
import com.chinasoft.mall.util.DateUtil;
import com.chinasoft.mall.util.StringUtil;
import com.chinasoft.mall.widget.NetImageView;
import com.chinasoft.mall.widget.NetShadowImageView;

public class HomePageActivity extends BaseObserverActivity implements
		OnClickListener, OnItemClickListener {

	private MyPagerAdapter mpa;
	private MyPagerBottomAdapter mbpa;
	private List<EpgViewInfo> listViews; // Tab页面列表
	private List<RechnViewInfo> bottomViews; // Tab页面列表
	private LayoutInflater mInflater; // Tab页面列表
	// 从表RECHN中读取，默认按发布日期排序。
	private BaseBean rechn;
	// 获取前一天或者当天或者后一天的节目单。]
	private BaseBean epg;
	// 将所属分类的商品全部显示出来
	private BaseBean goodsbyclass_bb;
	private String goodsbyclasstitle;

	private BaseBean modelweibo_bb;
	private String modelweibotitle;
	private String modelweiboimageurl;

	private GallaryImplAdapter giAdapter;
	private GallaryidImplAdapter botomAdapter;
	private ViewPager gallery;
	private ViewPager galleryid;
	
	private Object lock = new Object();
	private LinkedList<EpgBean> _ebs;
	private List<RechnBean> _rbs;
	private LinearLayout _ll;
	private LinearLayout line_ll;
	private int choiceId = 0;
	// 提示是否直播
	private SpannableString title;

	private ImageButton left;
	private ImageButton right;
	private ImageView playing_iv;
	//员工商城入口
	private ImageView stafflogin_btn;
	private TextView shop_tv;
	private int track=0;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sy);
		
		initData();
		initView();
		
	}

	private void initData() {
		Serializable sz=getIntent().getSerializableExtra(Config.INTENT_TRACK);
		if(sz!=null){
			track=(Integer) sz;
		}
	}

	private void initRequest() {
		rechn = BeanCache.getInstance().getResponsdata().get(Config.GET_RECHN);
		epg = BeanCache.getInstance().getResponsdata().get(Config.GET_EPG);

		Log.e("she qi a ", BeanCache.getBottomCache().size()+"");
		Log.e("rechbean ", "get date "+ ((ArrayList<RechnBean>)BeanCache.getInstance().getResponsdata().get(Config.GET_RECHN).getResData().getData()).size());
		if (rechn != null) {
			rechn.getResData().setData(BeanCache.getBottomCache());
			success(rechn);
			rechn.setAdd(true);
			control.postMessage(rechn);
		} else {
			rechn = new BaseBean(Config.GET_RECHN);
			rechn.setAdd(true);
			control.postMessage(rechn);
		}
		if (epg != null) {
			success(epg);
//			epg = new BaseBean(Config.GET_EPG);
//			control.postMessage(epg);
			Log.e("===================", "top 未请求");
		} else {
			epg = new BaseBean(Config.GET_EPG);
			control.postMessage(epg);
			success(epg);
			Log.e("===================", "top 请求");
		}

		
		// gallery.setOnItemClickListener(this);
//		galleryid.setOnItemClickListener(this);
		
	}

	private void initView() {
		left = (ImageButton) findViewById(R.id.left);
		right = (ImageButton) findViewById(R.id.right);
		playing_iv = (ImageView) findViewById(R.id.playing_iv);
		stafflogin_btn = (ImageView) findViewById(R.id.stafflogin_btn);
		shop_tv = (TextView) findViewById(R.id.shop_tv);
		_ll = (LinearLayout) findViewById(R.id._ll);
		line_ll = (LinearLayout) findViewById(R.id.line_ll);
		galleryid = (ViewPager) findViewById(R.id.galleryid);
		galleryid.setOnClickListener(this);
		gallery = (ViewPager) findViewById(R.id.gallery);
		giAdapter = new GallaryImplAdapter((MainActivity) this.getParent(),
				null);
		botomAdapter = new GallaryidImplAdapter((MainActivity) this.getParent(),
				null);
		listViews = new ArrayList<EpgViewInfo>();
		bottomViews = new ArrayList<RechnViewInfo>();
		mInflater = getLayoutInflater();
		mpa = new MyPagerAdapter();
		mbpa = new MyPagerBottomAdapter(bottomViews);
		gallery.setAdapter(mpa);
		gallery.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int arg0) {
				choiceId = arg0;
				topRefresh();
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {

			}
		});
		
		galleryid.setAdapter(mbpa);
//		galleryid.setAdapter(gidAdapter);
		galleryid.setOnPageChangeListener(new OnPageChangeListener() {
			
			@Override
			public void onPageSelected(int arg0) {
				// TODO Auto-generated method stub
				track=arg0;
				for (int i = 0; i < _ll.getChildCount(); i++) {
					if (i == track) {
						((ImageView) _ll.getChildAt(i))
								.setImageResource(R.drawable.blackpoint);
					} else {
						((ImageView) _ll.getChildAt(i))
								.setImageResource(R.drawable.graypoint);
					}
				}
			}
			
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
				
			}
		});
		stafflogin_btn.setOnClickListener(this);
		right.setOnClickListener(this);
		left.setOnClickListener(this);
	}
	
	private void topRefresh() {
		List<EpgBean> ebs  = _ebs;
		if(ebs==null||ebs.size()<=choiceId){
			return;
		}
		if (ebs.get(choiceId).getLivingState() == 0) {
			playing_iv.setVisibility(View.VISIBLE);
		} else {
			playing_iv.setVisibility(View.GONE);
		}
		title = new SpannableString(ebs.get(choiceId)
				.getLivingMessage()
				+ "  "
				+ DateUtil.format1Date(ebs.get(choiceId)
						.getFORM_FR_DATE())
				+ "-"
				+ DateUtil.format1Date(ebs.get(choiceId)
						.getFORM_END_DATE()));
		title.setSpan(new ForegroundColorSpan(Color.RED), 0,
				ebs.get(choiceId).getLivingMessage().length(),
				Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		shop_tv.setText(title);
		for (int i = 0; i < line_ll.getChildCount(); i++) {
			if (i == choiceId) {
				((ImageView) line_ll.getChildAt(i))
						.setImageResource(R.drawable.top_image);
			} else {
				((ImageView) line_ll.getChildAt(i))
						.setImageResource(R.drawable.top_image_shadow);
			}
		}
	}

	@Override
	protected void onResume() {
		super.onResume();
        new Handler().post(new Runnable() {
			
			@Override
			public void run() {
				initRequest();
			}
		});
	}

	public void createfoot(BaseBean obj) {
		_rbs = (ArrayList<RechnBean>) rechn.getResData().getData();
		if (_rbs != null && !_rbs.equals(botomAdapter.getData())) {
			botomAdapter.setData(_rbs);
			List<RechnViewInfo> mListViews=new ArrayList<RechnViewInfo>();
			int _ni=0;
			List<RechnBean> _eb=null;
			int max=_rbs.size();
			for(RechnBean rb:_rbs){
				if(_ni%3==0){
					_eb=new ArrayList<RechnBean>();
				}
				_eb.add(rb);
				if(_ni%3==2||((_ni+1)==max)){
					mListViews.add(new RechnViewInfo(mInflater.inflate(R.layout.gallerylv, null),_eb));
				}
				_ni++;
			}
			mbpa.setmListViews(mListViews);
//			_ll.removeAllViews();
//			for (int i = 0; i < gidAdapter.getCount(); i++) {
//				ImageView point = (ImageView) LayoutInflater.from(this)
//						.inflate(R.layout.point, null);
//				_ll.addView(point, i);
//			}
//			galleryid.setSelection(track);
//			galleryid.setCurrentItem(track);
		}
	}
	@SuppressWarnings("unchecked")
	@Override
	public void success(BaseBean obj) {
		super.success(obj);
		if (obj.equals(rechn)) {
			_rbs = (ArrayList<RechnBean>) rechn.getResData().getData();
			if (_rbs != null && !_rbs.equals(botomAdapter.getData())) {
				botomAdapter.setData(_rbs);
				List<RechnViewInfo> mListViews=new ArrayList<RechnViewInfo>();
				int _ni=0;
				List<RechnBean> _eb=null;
				int max=_rbs.size();
				for(RechnBean rb:_rbs){
					if(_ni%3==0){
						_eb=new ArrayList<RechnBean>();
					}
					_eb.add(rb);
					if(_ni%3==2||((_ni+1)==max)){
						mListViews.add(new RechnViewInfo(mInflater.inflate(R.layout.gallerylv, null),_eb));
					}
					_ni++;
				}
				mbpa.setmListViews(mListViews);
				_ll.removeAllViews();
				for (int i = 0; i < botomAdapter.getCount(); i++) {
					ImageView point = (ImageView) LayoutInflater.from(this)
							.inflate(R.layout.point, null);
					_ll.addView(point, i);
				}
//				galleryid.setSelection(track);
				galleryid.setCurrentItem(track);
			}
		} else if (obj.equals(epg)) {
			if (null != _ebs) {
				_ebs.clear();
			}
			_ebs = getEpgTop();
			if (_ebs != null) {//&& !_ebs.equals(giAdapter.getData())
				giAdapter.setData(_ebs);
				Log.e("回调","。。。。。。。。。。。");
				for (EpgBean eb : _ebs) {
					EpgViewInfo vi = new EpgViewInfo();
					vi.view = mInflater.inflate(R.layout.imagegv, null);
					vi.eb = eb;
					listViews.add(vi);
				}

				Log.e("top refresh ===================" , listViews.size()+"");
				
				mpa.setmListViews(listViews);

				line_ll.removeAllViews();
				for (int i = 0; i < _ebs.size(); i++) {
					LinearLayout _ll = (LinearLayout) LayoutInflater.from(this)
							.inflate(R.layout.line, null);
					ImageView line_iv = (ImageView) _ll
							.findViewById(R.id.line_iv);
					_ll.removeView(line_iv);
					line_ll.addView(line_iv, i);
				}
				gallery.setCurrentItem(choiceId);
				topRefresh();
			}
		} else if (obj.equals(modelweibo_bb)) {
			((MainActivity) HomePageActivity.this.getParent()).setCurrentActivity(
					SyModelList2Activity.class, modelweibotitle,
					modelweiboimageurl);
		}
		
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		switch (parent.getId()) {
		case R.id.gallery:
			List<EpgBean> ebs  = _ebs;
			((MainActivity) this.getParent()).setCurrentActivity(
					GoodsDetailActivity.class,ebs.get(position).getGOODS_NAME(), ebs.get(position));
			break;
		case R.id.galleryid:
			// spdetail=new BaseBean(Config.GET_GOODSIMG);
			// spdetail.reqData.put("goods_id",
			// _ebs.get(position).getGOODS_ID());
			// ((MainActivity)this.getParent()).setCurrentActivity(SpDetailActivity.class,_ebs.get(position).getGOODS_NAME(),
			// spdetail);
//			track=position;
//			((MainActivity) SyActivity.this.getParent()).setResultSz(track);
//			NetImageView gl_1 = (NetImageView) view.findViewById(R.id.gl_1);
//			NetImageView gl_2 = (NetImageView) view.findViewById(R.id.gl_2);
//			NetImageView gl_3 = (NetImageView) view.findViewById(R.id.gl_3);
//			RelativeLayout vp = (RelativeLayout) gl_1.getParent();
//			int lp_wide = vp.getMeasuredWidth();
//			Rect rect1 = new Rect(gl_1.getLeft(), gl_1.getTop(),
//					gl_1.getRight(), gl_1.getBottom());
//			Rect rect2 = new Rect(gl_2.getLeft() + lp_wide, gl_2.getTop(),
//					gl_2.getRight() + lp_wide, gl_2.getBottom());
//			Rect rect3 = new Rect(gl_3.getLeft() + lp_wide * 2, gl_3.getTop(),
//					gl_3.getRight() + lp_wide * 2, gl_3.getBottom());
//			int x = SyActivity.this.galleryid.point.x;
//			int y = SyActivity.this.galleryid.point.y;
//			Log.i("rect", "left:"+gl_1.getLeft()+",top:"+gl_1.getTop()+",right:"+gl_1.getRight()+",bottom:"+ gl_1.getBottom());
//			Log.i("rect", "touch::x="+x+"touch::y="+y);
//			
//			int _index = position * 3;
//			List<RechnBean> rbs = gidAdapter.getRbs();
//			int _max = rbs.size();
//			if (rect1.contains(x, y)) {
//			} else if (rect2.contains(x, y)) {
//				_index += 1;
//			} else if (rect3.contains(x, y)) {
//				_index += 2;
//			}else{
//				return;
//			}
//			RechnBean rb = _index >= _max ? null : rbs.get(_index);
//
//			requestBottom(rb);

			break;

		default:
			break;
		}
	}

	private void requestBottom(RechnBean rb,int position) {
		track=position;
		((MainActivity) HomePageActivity.this.getParent()).setResultSz(track);
		if (rb != null) {
			String type = rb.getTYPE();
			MainActivity activity = (MainActivity) HomePageActivity.this
					.getParent();
			// 2商品 3特价商品 4模特 5团购
			if (type.equals("2")) {
				activity.setCurrentActivity(GoodsDetailActivity.class,
						rb.getTITLE(), rb);
			} else if (type.equals("3")) {
				RechnBean splist = new RechnBean();
				splist.setID(rb.getID());
				splist.setTYPE("3");
				activity.setCurrentActivity(GoodsDetailActivity.class,rb.getTITLE(), splist);
			} else if (type.equals("4")) {
				modelweiboimageurl = StringUtil.modelImageUrl(rb.getID(),rb.getTHUM());
				modelweibotitle = rb.getTITLE();
				modelweibo_bb = new BaseBean(Config.GET_MODELWEIBO);
				modelweibo_bb.reqData.put("pageNo", "1");
				modelweibo_bb.reqData.put("pageSize", "10");
				modelweibo_bb.reqData.put("model_id", rb.getID());
				control.sendMessage(modelweibo_bb);
			} else if (type.equals("5")) {
				goodsbyclasstitle = rb.getTITLE();
//				else if (obj.equals(goodsbyclass_bb)) {
					((MainActivity) HomePageActivity.this.getParent()).setCurrentActivity(
							GoodsListFromHomeActivity.class, rb.getTITLE(),rb);
//				} 
				
			}
		}
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		return super.onTouchEvent(event);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.left:
			if(choiceId>0){
				gallery.setCurrentItem(--choiceId);
			}
			break;
		case R.id.right:
			if(choiceId<5){
				gallery.setCurrentItem(++choiceId);
			}
			break;
		case R.id.stafflogin_btn:
			((MainActivity) HomePageActivity.this.getParent()).setCurrentActivity(
					StaffLoginActivity.class, this.getString(R.string.stafflogin));
			break;
		default:
			break;
		}
	}

	@Override
	public void updateActivity(Observable observable, Object data) {
		int refreshtype = (Integer) data;
		if (refreshtype == LivingGoods.Refresh_PLAY) {
			LinkedList<EpgBean> ebs = getEpgTop();
			List<EpgBean> list = giAdapter.getData();
			if (ebs != null) {
				if(!ebs.equals(list))
				{
				giAdapter.setData(ebs);
					if (ebs.size() > choiceId
							&& ebs.get(choiceId).getLivingState() == 0) {
						playing_iv.setVisibility(View.VISIBLE);
					} else {
						playing_iv.setVisibility(View.GONE);
					}
				title = new SpannableString(ebs.get(choiceId)
						.getLivingMessage()
						+ "  "
						+ DateUtil.format1Date(ebs.get(choiceId)
								.getFORM_FR_DATE())
						+ "-"
						+ DateUtil.format1Date(ebs.get(choiceId)
								.getFORM_END_DATE()));
				title.setSpan(new ForegroundColorSpan(Color.RED), 0,
						ebs.get(choiceId).getLivingMessage().length(),
						Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
				shop_tv.setText(title);
				gallery.setCurrentItem(choiceId);
			}
			}
		}
	}

	private synchronized LinkedList<EpgBean> getEpgTop() {
		LinkedList<EpgBean> _ebs = LivingGoods.getInstance().getLiving_ebs();
		if (_ebs.size() >= 5) {
			LinkedList<EpgBean> ebs = new LinkedList<EpgBean>();
			for(int i = 0; i < 5;i++)
			{
				ebs.add(_ebs.get(i));
			}
			return ebs;
		} else {
			choiceId = 0;
			LinkedList<EpgBean> _lebs = new LinkedList<EpgBean>(_ebs);
			List<EpgBean> wait_ebs = LivingGoods.getInstance().getWait_ebs();
			List<EpgBean> lived_ebs = LivingGoods.getInstance().getLived_ebs();
			int waitid = 0;
			int waitsize = wait_ebs.size();
			int lived = lived_ebs.size();
			boolean isLeft = true;
			for (int i = 0; i < 5 - _ebs.size(); i++) {
				if (waitid < waitsize && isLeft) {
					_lebs.addLast(wait_ebs.get(waitid++));
					isLeft = false;
				} else if (lived > 0 && !isLeft) {
					choiceId++;
					_lebs.addFirst(lived_ebs.get(--lived));
					isLeft = true;
				} else {
					if (waitid < waitsize) {
						_lebs.addLast(wait_ebs.get(waitid++));
					} else if (lived > 0) {
						choiceId++;
						_lebs.addFirst(lived_ebs.get(--lived));
					}
					isLeft = !isLeft;
				}
			}
			// gallery.setSelection(choiceId);
			return _lebs;
		}
	}

	public class EpgViewInfo {
		View view;
		EpgBean eb;
	}
	public class RechnViewInfo {
		View view;
		List<RechnBean> eb;
		public RechnViewInfo(View view, List<RechnBean> eb) {
			super();
			this.view = view;
			this.eb = eb;
		}
	}
	/**
	 * ViewPager适配器
	 */
	public class MyPagerAdapter extends PagerAdapter {

//		public List<EpgViewInfo> mListViews;

		public MyPagerAdapter() {
//			this.mListViews = mListViews;
		}

		public void setmListViews(List<EpgViewInfo> mListViews) {
//			this.mListViews = mListViews;
			this.notifyDataSetChanged();
		}

		@Override
		public void destroyItem(View arg0, int arg1, Object arg2) {
			((ViewPager) arg0).removeView(listViews.get(arg1).view);
		}

		@Override
		public void finishUpdate(View arg0) {
		}

		@Override
		public int getCount() {
			return listViews.size();
		}

		@Override
		public Object instantiateItem(View arg0, int arg1) {
			View v = listViews.get(arg1).view;
			NetImageView _niv=((NetImageView) v.findViewById(R.id.netimage));
			_niv.setDownload(StringUtil.shopUrl(listViews.get(arg1).eb
					.getGOODS_ID(),listViews.get(arg1).eb.getFOCUS()));
			final EpgBean _eb=listViews.get(arg1).eb;
			_niv.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					((MainActivity) HomePageActivity.this.getParent()).setCurrentActivity(
							GoodsDetailActivity.class,_eb.getGOODS_NAME(),_eb);
				}
			});
			((ViewPager) arg0).addView(v, 0);
			return v;
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			return arg0 == (arg1);
		}

		@Override
		public void restoreState(Parcelable arg0, ClassLoader arg1) {
		}

		@Override	
		public Parcelable saveState() {
			return null;
		}

		@Override
		public void startUpdate(View arg0) {
		}
	}
	
	class ViewHolder {
		public NetShadowImageView gl_1;
		public TextView tv_1;
		public NetShadowImageView gl_2;
		public TextView tv_2;
		public NetShadowImageView gl_3;
		public TextView tv_3;
	}
	
	/**
	 * ViewPager适配器
	 */
	public class MyPagerBottomAdapter extends PagerAdapter {

		public List<RechnViewInfo> mListViews;
		public ViewHolder _vh;

		public MyPagerBottomAdapter(List<RechnViewInfo> mListViews) {
			this.mListViews = mListViews;
		}

		public void setmListViews(List<RechnViewInfo> mListViews) {
			this.mListViews = mListViews;
			this.notifyDataSetChanged();
		}

		@Override
		public void destroyItem(View arg0, int arg1, Object arg2) {
			((ViewPager) arg0).removeView(mListViews.get(arg1).view);
		}

		@Override
		public void finishUpdate(View arg0) {
		}

		@Override
		public int getCount() {
			return mListViews.size();
		}
		
		public String translateUrl(RechnBean _rb){
			String type=_rb.getTYPE();
			if(type.equals("4")){
				return StringUtil.modelImageUrl(_rb.getID(),_rb.getTHUM());
			}else if(type.equals("3")){
				return StringUtil.grpBreviaryUrl(_rb.getID(),_rb.getTHUM());
			}else if(type.equals("5")){
				return StringUtil.goodsSpUrl(_rb.getID(),_rb.getTHUM());
			}else{
				return StringUtil.goodUrl(_rb.getID(),_rb.getTHUM());
			}
		}

		@Override
		public Object instantiateItem(View arg0, int arg1) {
			View v = mListViews.get(arg1).view;
			List<RechnBean> rbs=mListViews.get(arg1).eb;
			_vh = new ViewHolder();
			
			_vh.gl_1 = (NetShadowImageView) v.findViewById(R.id.gl_1);
			_vh.tv_1 = (TextView) v.findViewById(R.id.tv_1);
			_vh.gl_2 = (NetShadowImageView) v.findViewById(R.id.gl_2);
			_vh.tv_2 = (TextView) v.findViewById(R.id.tv_2);
			_vh.gl_3 = (NetShadowImageView) v.findViewById(R.id.gl_3);
			_vh.tv_3 = (TextView) v.findViewById(R.id.tv_3);
			
			
			int _index = 0;
			int _max = rbs.size();
			RechnBean _rb = rbs.get(_index);
			if (_index + 1 <= _max) {
				_vh.tv_1.setText(_rb.getTITLE());
				_vh.gl_1.setDownloadurl(translateUrl(_rb));
				_vh.gl_1.setOnClickListener(new onClickImpl(_rb,arg1));
			}
			_index++;
			_rb = rbs.get(_index);
			if (_index + 1 <= _max) {
				_vh.tv_2.setText(_rb.getTITLE());
				_vh.gl_2.setDownloadurl(translateUrl(_rb));
				_vh.gl_2.setOnClickListener(new onClickImpl(_rb,arg1));
			}
			_index++;
			_rb = rbs.get(_index);
			if (_index + 1 <= _max) {
				_vh.tv_3.setText(_rb.getTITLE());
				_vh.gl_3.setDownloadurl(translateUrl(_rb));
				_vh.gl_3.setOnClickListener(new onClickImpl(_rb,arg1));
			}
			
//			NetImageView _niv=((NetImageView) v.findViewById(R.id.netimage));
//			_niv.setDownload(StringUtil.shopUrl(mListViews.get(arg1).eb
//					.getGOODS_ID(),mListViews.get(arg1).eb.getFOCUS()));
//			final EpgBean _eb=mListViews.get(arg1).eb;
//			_niv.setOnClickListener(new OnClickListener() {
//				
//				@Override
//				public void onClick(View v) {
//					// TODO Auto-generated method stub
//					((MainActivity) SyActivity.this.getParent()).setCurrentActivity(
//							SpDetailActivity.class,_eb);
//				}
//			});
			((ViewPager) arg0).addView(v, 0);
			return v;
		}
		
		class onClickImpl implements View.OnClickListener{
			private RechnBean _rb;
			private int position;
			
			public onClickImpl(RechnBean _rb,int position) {
				// TODO Auto-generated constructor stub
				this._rb=_rb;
				this.position=position;
			}

			@Override
			public void onClick(View v) {
				requestBottom(_rb,position);
			}
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			return arg0 == (arg1);
		}

		@Override
		public void restoreState(Parcelable arg0, ClassLoader arg1) {
		}

		@Override
		public Parcelable saveState() {
			return null;
		}

		@Override
		public void startUpdate(View arg0) {
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		listViews.clear(); // Tab页面列表
		bottomViews.clear(); // Tab页面列表
		_ebs.clear();
		_rbs.clear();
		choiceId = 0;
	}
	
	
}
